package com.dotflat.physicalevaluate.service.impl.chart;


import org.springframework.stereotype.Service;

import java.util.Map;


@Service
public class RemoteLineChartServiceImpl extends AbstractRemoteHighChartService {

    private static final String JSON_TEMPLATE = "{ \"infile\":{" +
            " \"credits\": {" +
            "    \"enabled\": false" +
            " }, " +
            " \"title\": { " +
            "  \"text\": \"#title\" " +
            " }, " +
            " \"yAxis\": { " +
            "  \"title\": { " +
            "   \"text\": \"\" " +
            "  } " +
            " }, " +
            " \"legend\": { " +
            "  \"layout\": \"vertical\", " +
            "  \"align\": \"right\", " +
            "  \"verticalAlign\": \"middle\" " +
            " }, " +
            " \"xAxis\": { " +
            "  \"categories\": [#categories] " +
            " }, " +
            " \"series\": [#series], " +
            " \"plotOptions\": { " +
            "  \"line\": { " +
            "   \"dataLabels\": { " +
            "    \"enabled\": true           " +
            "   }, " +
            "   \"enableMouseTracking\": false " +
            "  } " +
            " }, " +
            " \"responsive\": { " +
            "  \"rules\": [{ " +
            "   \"condition\": { " +
            "    \"maxWidth\": 500 " +
            "   }, " +
            "   \"chartOptions\": { " +
            "    \"legend\": { " +
            "     \"layout\": \"horizontal\", " +
            "     \"align\": \"center\", " +
            "     \"verticalAlign\": \"bottom\" " +
            "    } " +
            "   } " +
            "  }] " +
            " } " +
            "}}";



    public byte[] getRemoteEvaluateChart(Map dataMap) {
        String title = (String)dataMap.get("title");
        String categories = (String)dataMap.get("categories");
        String series = (String)dataMap.get("series");

        String jsonData = JSON_TEMPLATE.replace("#title",title);
        jsonData = jsonData.replace("#categories",categories);
        jsonData = jsonData.replace("#series",series);

        System.out.println("*********************begin******************");
        System.out.println(jsonData);
        System.out.println("**********************end*******************");
        //0,0,0,0,0,0,0
        return binaryHTTPCall(chartServerURL, jsonData, "创建测评结果图表时异常");
    }
}
